package com.lijy.list;

public class Item implements Comparable<Item> {

    private String description;
    private int partNumber;

    public Item(String description, int partNumber) {
        this.description = description;
        this.partNumber = partNumber;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public int getPartNumber() {
        return partNumber;
    }

    public void setPartNumber(int partNumber) {
        this.partNumber = partNumber;
    }

    @Override
    public String toString() {
        return "{" +
                "description='" + description + '\'' +
                ", partNumber=" + partNumber +
                '}';
    }

    @Override
    public int hashCode() {
        int result = 17;
        result = result * 31 + description.hashCode();
        result = result * 31 + partNumber;

        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }

        if (obj == null) {
            return false;
        }

        if (getClass() != obj.getClass()) {
            return false;
        }

        Item other = (Item) obj;
        return other.description.equals(description)
                && other.partNumber == partNumber;
    }

    public int compareTo(Item o) {
        int status = this.description.compareTo(o.getDescription());
        if (status == 0) {
            return this.partNumber - o.partNumber;
        }
        return status;
    }
}
